package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Course;
import com.qk.mapper.CourseMapper;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl  implements CourseService {

    @Autowired
    private CourseMapper courseMapper;


    @Override
    public void deleteById(Integer id) {//删除部门
        courseMapper.deleteById(id);
    }

    @Override
    public PageResult<Course> list(Integer subject, Integer target, Integer page, Integer pageSize) {
        //1．设置PageHeLper分页参数
        PageHelper.startPage(page,pageSize);
        //2．调用mapper接口方法，执行查询
        List<Course> deptList =courseMapper.list(subject,target);
        //3．解析并封装分页结果
        Page<Course> p =(Page<Course>) deptList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }
    @Override
    public void add(Course course) {//添加部门
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.add(course);

    }
    @Override
    public Course getById(Integer id) {//获取部门信息
            return courseMapper.selectById(id);
    }

    @Override
    public void update(Course course) {//修改部门信息
         course.setUpdateTime(LocalDateTime.now());
         courseMapper.update(course);
    }
    @Override
    public List<Course> listAll() {
        List<Course> courses = courseMapper.listAll();
        return List.of();
    }
    @Override
    public List<Course> listBySubject(Integer subject) {
        return courseMapper.listBySubject(subject);
    }


}
